<template>
	<view class="">
		<view class="page-bg-gray"></view>
		<view class="address-select-box">
			<view class="address-select-box-main" @click="selectAddress">
				<view class="address-info">
					<view class="address-selected" v-if="this.addressInfo !== null">
						<view class="top">
							<view class="name">{{ addressInfo.customerUserName }}</view>
							<view class="phone">{{ addressInfo.shippingPhone }}</view>
							<view class="tag">
								<text :class="{blue:addressInfo.isDefault=== 1}">默认</text>
							</view>
						</view>
						<view class="bottom">
							{{ addressInfo.address }}
						</view>
					</view>
					<view class="address-not" v-else>
						<u-icon name="map" size="46"></u-icon>
						<text class="text">选择收货地址</text>

					</view>
				</view>
				<!-- <view class="icon">
					<u-icon name="arrow-right" color="#CCC" size="36"></u-icon>
				</view> -->
				<!-- <view class="address-bg-img"></view> -->
			</view>
		</view>
		<view class="goods-box">
			<view class="order" v-for="(res, index) in orderList" :key="res.id">
				<view class="top">
					<view class="left">
						<u-icon name="home" :size="30" color="rgb(94,94,94)"></u-icon>
						<view class="store">{{ res.storeName }}</view>
					</view>
				</view>
				<view class="item">
					<view class="left">
						<image :src="res.goodPic" mode="aspectFill"></image>
					</view>
					<view class="content">
						<view class="title u-line-2">{{ res.goodsName }}</view>
						<view class="type">{{ res.goodsDesc }}</view>
						<view class="delivery-time">发货时间 付款后2天发货</view>
					</view>
					<view class="right">
						<view class="price">
							￥{{res.goodsMoney /100}}
							<!-- <text class="decimal">.1</text> -->
						</view>
						<view class="number">x{{ res.orderCount }}</view>
					</view>
				</view>
				<view class="total">
					共{{ res.orderCount }}件 小计:
					<text class="total-price">
						￥{{res.goodsMoney / 100 * res.orderCount }}
						<!-- <text class="decimal">2</text> -->
					</text>
				</view>
			</view>
		</view>

		<view class="other-box">
			<u-cell-group class="group">
				<u-cell-item title="商品总额" :arrow="false" hover-class="cell-hover-class">
					<view slot="right-icon" class="">
						￥{{orderThree.zonge}}
					</view>
				</u-cell-item>
				<u-cell-item title="商品数量" :arrow="false" hover-class="cell-hover-class">
					<view slot="right-icon" class="">
						{{orderThree.value}}
					</view>
				</u-cell-item>
				<u-cell-item title="运费" :arrow="false" hover-class="cell-hover-class">
					<view slot="right-icon" class="">
						包邮
					</view>
				</u-cell-item>
				<u-cell-item @click="gotoUseCoupon">
					<view slot="title" class="">
						优惠券<text class="coupon-discount"
							v-if="selectCoupons.length > 0">(已选{{selectCoupons.length}}张)</text>
					</view>
					<view slot="right-icon" class="">
						<view class="coupon-not" v-if="couponList.length < 1">无可用</view>
						<view class="coupon-select" v-if="couponList.length > 0 && selectCoupons.length < 1">去选择</view>
						<view class="coupon-discount" v-if="selectCoupons.length > 0">-￥10.00</view>
					</view>
				</u-cell-item>
				<u-cell-item title="发票" @click="gotoUseInvoice">
					<view slot="right-icon" class="">
						不开发票
					</view>
				</u-cell-item>
				<u-cell-item :arrow="false" hover-class="cell-hover-class">
					<view slot="right-icon" class="">
						合计：<text class="price">￥{{orderThree.zonge}}</text>
					</view>
				</u-cell-item>
			</u-cell-group>
		</view>

		<view class="order-create-tabbar-area-bottom"></view>
		<view class="order-create-tabbar">
			<view class="left">
				<text>共<text class="goods-num">{{zognshu}}</text>件</text>,
				<text>应付:<text class="price">￥{{orderThree.zonge}}</text></text>
			</view>
			<view class="right">
				<u-button type="error" size="medium" shape="circle" :hairLine="false" :loading="submitBtnLoading"
					@click="submitOrderDetail">提交订单</u-button>
			</view>
		</view>

		<!-- 支付方式模态框 -->

	</view>
</template>

<script>
	import request from '../../../utils/request.js'
	import paytype from '../../../common/i-pay-type.vue'
	export default {
		components: {
			paytype
		},
		computed: {
			// 价格小数
			priceDecimal() {
				return val => {
					if (val !== parseInt(val)) return val.slice(-2);
					else return '00';
				};
			},
			// 价格整数
			priceInt() {
				return val => {
					if (val !== parseInt(val)) return val.split('.')[0];
					else return val;
				};
			}
		},
		data() {
			return {
				addressInfo: {},
				couponList: [],
				selectCoupons: [],
				submitBtnLoading: false,
				orderList: [],
				otherl: {},
				countg: '',
				zognshu: '',
				isshow: false,
				orderThree:{
					addressId:'',
					userid: '',
					detail:undefined,
					zonge: '',
					value:''
				}
			}
		},
		/* 页面加载 */
		onLoad(options) {
			const item = options.to
			const detail=options.DETAIL
			const value=options.value
			console.log(item)
			console.log(detail)
			this.orderThree.detail=detail
			this.orderThree.zonge = item
			this.orderThree.value=value
			this.countg = item.orderCount
			/* 查询该用户的默认地址 */
			this.getAddress();
			
		},
		methods: {
			submitOrderDetail(){
				let ooThree = encodeURIComponent(JSON.stringify(this.orderThree))
				uni.navigateTo({
					url:'../../user/money/pay?to='+ooThree
				})
			},
			cc(e) {
				console.log(e);
				this.goodsOrder.orderPay = e
			},
			/* 提交订单 */
			submitOrder() {
				this.goodsOrder.orderMoney = this.zonge
				this.goodsOrder.shipId = this.addressInfo.shipId
				console.log(this.goodsOrder);
				request({
					url: '/order/goodsorder/submitOrder',
					data: this.goodsOrder,
					method: 'POST',
					success: (res) => {
						console.log("详细", res.data);
						this.otherl = res.data.data.data
						for (let i = 0; i < res.data.data.data.goodsPic.length; i++) {
							this.otherl.goodsPic = res.data.data.data.goodsPic[0]
						}
						console.log(this.otherl.goodsPic);
						/* 查询商铺信息 */
						this.getstore(res.data.data.data.storeId);
					}
				})
			},
		
			getstore(storeId) {
				request({
					url: '/goods/goods/getshopInfo',
					data: {
						storeId: storeId
					},
					success: (res) => {
						console.log(res.data);
						this.otherl.storeName = res.data.data.data.storeName
						this.otherl.orderCount = this.countg
						this.orderList.push(this.otherl)
						this.zonge = (this.otherl.goodsMoney / 100 * this.otherl.orderCount)
						this.zognshu = this.otherl.orderCount
						console.log(this.orderList);
					}
				})
			},
			getAddress() {
				uni.getStorage({
					key: 'beforeUser',
					success: (res) => {
						this.orderThree.userid = res.data.beforeUserId
						console.log(this.orderThree.userid)

					}
				})
				request({
					url: '/before/bgs/customer-addr/TowListAdd',
					method: 'Get',
					data: {
						beforeUserId: this.orderThree.userid
					},
					success: (res) => {
						console.log(res);
						var item = res.data.data.list
						item.forEach(rr => {
							if (rr.isDefault === 1) {
								this.addressInfo = rr
								this.orderThree.addressId=rr.beforeUserAddrId
								console.log(this.orderThree.addressId)
							}
						})
					}
				})
			},



		}

	}
</script>

<style lang="scss">
	@import '@/static/css/member_order_list.scss';

	.address-select-box {
		// margin-top: 20rpx;
		position: relative;
		padding: 20rpx 20rpx 0 20rpx;

		.address-select-box-main {
			display: flex;
			background-color: #FFF;
			justify-content: space-between;
			border-radius: 20rpx;
		}

		.icon {
			display: flex;
			align-items: center;
			justify-content: center;
			flex-direction: column;
			margin-right: 20rpx;
		}
	}

	.address-not {
		padding: 40rpx 40rpx;
		font-size: 36rpx;

		.text {
			margin-left: 10rpx;
		}
	}

	.address-bg-img {
		position: absolute;
		width: 100%;
		height: 8rpx;
		left: 0;
		bottom: 0;
		background: url("") repeat;
	}

	.address-selected {
		padding: 40rpx 40rpx;

		.top {
			display: flex;
			font-weight: bold;
			font-size: 34rpx;

			.phone {
				margin-left: 60rpx;
			}

			.tag {
				display: flex;
				font-weight: normal;
				align-items: center;

				text {
					display: block;
					width: 60rpx;
					height: 34rpx;
					line-height: 34rpx;
					color: #ffffff;
					font-size: 20rpx;
					border-radius: 6rpx;
					text-align: center;
					margin-left: 30rpx;
					background-color: rgb(49, 145, 253);
				}

				.red {
					background-color: red
				}
			}
		}

		.bottom {
			display: flex;
			margin-top: 20rpx;
			font-size: 28rpx;
			justify-content: space-between;
			color: #999999;
		}
	}

	.goods-box {}

	.order-create-tabbar-area-bottom {
		height: 120rpx;
	}

	.order-create-tabbar {
		border-top: 1px solid #CCC;
		background-color: #FFF;
		display: flex;
		width: 100%;
		height: 100rpx;
		line-height: 100rpx;
		position: fixed;
		padding: 0 30rpx;
		bottom: 0;
		justify-content: space-between;

		.left {
			font-size: 32rpx;
			color: #6a6a6a;

			.goods-num {
				color: #000000;
				font-weight: 700;
			}
		}
	}

	.price {
		color: #E41F19;
		font-weight: 700;
	}

	.coupon-not {}

	.coupon-select {
		color: #333;
	}

	.coupon-discount {
		color: #E41F19;
	}

	.cell-hover-class {}

	.other-box {
		margin: 20rpx;

		.group {
			border-radius: 20rpx;

			/deep/ .u-cell-item-box {
				border-radius: 20rpx;
			}
		}
	}
</style>
